//
//  UILabel+NSAttributeString.m
//  SafeFoodManagerDemo
//
//  Created by bob on 2017/10/19.
//  Copyright © 2017年 bob. All rights reserved.
//

#import "UILabel+NSAttributeString.h"

@implementation UILabel (NSAttributeString)

-(NSAttributedString*)MarkWithStr:(NSString*)Str
{
      NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:Str];
    
    NSString*sub=[Str substringFromIndex:Str.length-1];
    
    if ([sub isEqualToString:@"*"]) {
        
        [AttributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(Str.length-1, 1)];
        
    }else{

    }

    return AttributedStr;
}


-(NSAttributedString*)NumWithStr:(NSString*)Str
{
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:Str];
    [AttributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(0, 1)];

    return AttributedStr;
    
}


-(NSAttributedString*)StartWithStr:(NSString*)Str
{
    
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:Str];
    
    NSString*sub=[Str substringFromIndex:Str.length-1];
    
    if ([sub isEqualToString:@"☆"]) {
        
        [AttributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(Str.length-1, 1)];
        
    }
    
    return AttributedStr;
    
}

//拼接的富文本
-(NSAttributedString*)appStr:(NSString*)titleStr andContenStr:(NSString*)ContentStr
{
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@:%@",titleStr,ContentStr]];
    
      [AttributedStr addAttribute:NSForegroundColorAttributeName value:TBColorSubTitle range:NSMakeRange(0, titleStr.length+1)];
    
    return AttributedStr;
}

//检查记录
-(NSAttributedString*)appShopName:(NSString*)ShopName andCheckList:(NSString*)CheckList
{
    
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@\n%@",ShopName,CheckList]];
    
    [AttributedStr addAttribute:NSForegroundColorAttributeName value:TBColorSubTitle range:NSMakeRange(ShopName.length+1, CheckList.length)];
    
     [AttributedStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:NSMakeRange(ShopName.length+1, CheckList.length)];

    return AttributedStr;
    
}

@end
